package com.linkoog.devtools.utils;

import java.io.ByteArrayOutputStream;
import java.io.Closeable;
import java.io.InputStream;

public class IOUtils {

    public static void quietClose(Closeable closeable) {
        try {
            if (closeable != null) closeable.close();
        }catch (Exception ignore) {
        }
    }

    /**
     * 读取 InputStream 到 String字符串中
     */
    public static String readToString(InputStream in) {
        try (ByteArrayOutputStream baos = new ByteArrayOutputStream()){
            byte[] buffer = new byte[1024];
            int len = -1;
            while ((len = in.read(buffer)) != -1) {
                baos.write(buffer, 0, len);
            }
            return baos.toString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }
}
